﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Items : MonoBehaviour
{
    public int bombs = 0;
    public int score = 0, last = 0;

    public AudioClip[] tauntClips;
    public AudioSource heroAS;

    public GameObject bomb;
    public Text scoreShow, bombNum;
    // Start is called before the first frame update
    private void Start()
    {
        heroAS = GameObject.Find("Hero").GetComponent<AudioSource>();
        //scoreShow = GameObject.Find("Canvas").transform.Find("score").GetComponent<Text>();
        //bombNum = GameObject.Find("Canvas").transform.Find("bomb").GetComponent<Text>();
    }
    private void Update()
    {
        if (score / 500 > last)
        {
            heroAS.PlayOneShot(tauntClips[Random.Range(2, tauntClips.Length)]);
            last = score / 500;
        }
        if (Input.GetButtonDown("Fire2")) layBomb();
        //scoreShow.text = score.ToString();
        //bombNum.text = bombs.ToString();
    }

    public void getBomb()
    {
        bombs++;
        heroAS.PlayOneShot(tauntClips[0]);
    }

    void layBomb()
    {
        if(bombs > 0)
        {
            int d = 2 * (GetComponent<PlayerControl>().FaceR ? 1 : 0) - 1;
            heroAS.PlayOneShot(tauntClips[1]);
            Instantiate(bomb, transform.position + Vector3.right * d, Quaternion.identity);
            bombs--;
        }
    }
    public void getHeal()
    {
        heroAS.PlayOneShot(tauntClips[9]);
    }
}
